package com.boot.security.server.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.boot.security.server.model.AppAccount;

@Mapper
public interface AppAccountDao {

    @Select("select * from app_account t where t.id = #{id}")
    AppAccount getById(Long id);

    @Delete("delete from app_account where id = #{id}")
    int delete(Long id);

    int update(AppAccount appAccount);
    
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into app_account(accountid, openId, nickname, sex, language, city, province, country, headImageUrl, subscribeTime, subscribe, realName, idCard, phoneNo, patientCount, accountStatus, patientid, times, userid, cardtype, codecm1, codecm2, codecm3, xzz, gzdw, ybrgx, host_code, famtime, csrq, age, blanefee,cardno, responsetype) values(#{accountid}, #{openId}, #{nickname}, #{sex}, #{language}, #{city}, #{province}, #{country}, #{headImageUrl}, #{subscribeTime}, #{subscribe}, #{realName}, #{idCard}, #{phoneNo}, #{patientCount}, #{accountStatus}, #{patientid}, #{times}, #{userid}, #{cardtype}, #{codecm1}, #{codecm2}, #{codecm3}, #{xzz}, #{gzdw}, #{ybrgx}, #{hostCode}, #{famtime}, #{csrq}, #{age}, #{blanefee}, #{cardno}, #{responsetype})")
    int save(AppAccount appAccount);
    
    int count(@Param("params") Map<String, Object> params);

    List<AppAccount> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);
    //@Select("select * from app_account t where t.openId = #{openId} or  t.cardno = #{cardno} or  (t.idCard = #{idCard} and  t.cardtype = #{cardtype})  or  t.phoneNo = #{phoneNo}  ")
    AppAccount  getBylist(@Param("params") AppAccount appAccount);
    @Select("select * from app_account t where t.openId = #{openId} or  t.cardno = #{cardno} or  t.idCard = #{idCard} or  t.cardtype = #{cardtype}  or  t.phoneNo = #{phoneNo}  ")
    List<AppAccount> getBydtolist(@Param("openId") String openId, @Param("cardno") String cardno, @Param("idCard") String idCard,@Param("cardtype") String cardtype,@Param("phoneNo") String phoneNo);

    @Select("select * from app_account t where t.openId = #{openId} or t.phoneNo = #{phoneNo}  ")
    AppAccount  getByusers(@Param("openId") String openId,@Param("phoneNo") String phoneNo);

}
